package main

import (
	"fmt"
	"github.com/gomodule/redigo/redis"
)

func main() {
	sp, err := redis.Dial("tcp", fmt.Sprintf("%s:%d", "127.0.0.12.9", 6379))
	if err != nil {
		return
	}
	defer sp.Close()

	spc := redis.PubSubConn{Conn: sp}
	if false {
		// c.Do = c.Send + c.Flush + c.Receive
		spc.Subscribe("news.it")
		for {
			switch v := spc.Receive().(type) {
			case redis.Message:
				fmt.Printf("%s message: %s\n", v.Channel, v.Data)
			case redis.Subscription: // 是否注册成功的消息
				fmt.Printf("%s: %s %d\n", v.Channel, v.Kind, v.Count)
			case error:
				return
			}
		}
	}

	if false {
		// it showbz cars
		spc.PSubscribe("news.*")
		for {
			switch v := spc.Receive().(type) {
			case redis.PMessage:
				fmt.Printf("%s: pmessage: %s\n", v.Channel, v.Data)
			case redis.Subscription: // 是否注册成功的消息
				fmt.Printf("%s: %s %d\n", v.Channel, v.Kind, v.Count)
			case error:
				return
			}
		}
	}

}
